package StudyCode.summary.mydatetime;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class UsingGregorianCalendar {
	public static void main(String[] args) {
		GregorianCalendar gc = new GregorianCalendar();
		System.out.println("当前日期: " + getStr(gc));

		gc.add(Calendar.YEAR, 1);
		System.out.println("加一年后: " + getStr(gc));

		gc.add(Calendar.DATE, 15);
		System.out.println("加15天后: " + getStr(gc));

		long millis = gc.getTimeInMillis();
		Date dt = gc.getTime();
		System.out.println("时间(单位:毫秒): " + millis);
		System.out.println("Date 时间: " + dt);
	}

	private static String getStr(GregorianCalendar gc) {
		int day = gc.get(Calendar.DAY_OF_MONTH);
		int month = gc.get(Calendar.MONTH);
		int year = gc.get(Calendar.YEAR);
		int hour = gc.get(Calendar.HOUR);
		int minute = gc.get(Calendar.MINUTE);
		int second = gc.get(Calendar.SECOND);

		return day + "/" + (month + 1) + "/" + year + " " + hour + ":" + minute + ":" + second;
	}
}
